package com.study.mike.model.dto;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.study.mike.model.po.UserImportPO;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author KangHui
 * @Date 2023/3/23 16:26
 */
@Slf4j
public class ImportUserInfoListener extends AnalysisEventListener<UserImportPO> {

    @Getter
    private final List<UserImportPO> userList = new ArrayList<>(10);

    /**
     * 解析每条数据
     * @param user
     * @param analysisContext
     */
    @Override
    public void invoke(UserImportPO user, AnalysisContext analysisContext) {
      userList.add(user);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    @Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
        super.onException(exception, context);
        log.error("导入批量文件异常", exception);
    }
}
